package com.baibei.ebec.quotation;


import android.util.SparseArray;

import com.baibei.model.QuotationInfo;


/**
 * 行情缓存
 * Created by ChenRui on 2017/5/23 0023 18:40.
 */
public final class QuotationInfoCache {

    // 缓存
    private final static SparseArray<QuotationInfo> instance = new SparseArray<>();

    public static void cache(QuotationInfo m) {
        instance.put(m.getProductCode(), m);
    }

    public static SparseArray<QuotationInfo> get() {
        return instance;
    }

    /**
     * 获取缓存对象，没有会自动创建对象
     *
     * @param productId 产品
     * @return 一定不为空对象
     */
    public static QuotationInfo get(int productId) {
        QuotationInfo m = instance.get(productId);
        if (m == null) {
            m = new QuotationInfo();
            m.setProductCode(productId); // 产品ID
            cache(m); // 缓存
        }
        return m;
    }

    private QuotationInfoCache() {
    }


    public static void clear() {
        instance.clear();
    }
}
